package com.hitsoyauce.mail.view;

import java.awt.Font;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.KeyEvent;

import javax.swing.JMenu;
import javax.swing.JMenuBar;
import javax.swing.JMenuItem;
import javax.swing.JOptionPane;

public class MenuBar extends JMenuBar implements ActionListener {

	private static final long serialVersionUID = 5678890756340537476L;
	private MainWindow parent;
	
	public MenuBar(MainWindow parent) {
		this.parent = parent;
		add(createJMenu("文件", createNenuItem("日报选择..."), createNenuItem("关闭")));
		add(createJMenu("设置", createNenuItem("账户设置...")));
		add(createJMenu("帮助", createNenuItem("使用说明"), createNenuItem("关于")));
		setVisible(true);
	}

	private JMenu createJMenu(String menuName, JMenuItem... menuItems) {
		JMenu menu = new JMenu(menuName);
		menu.setFont(new Font("宋体", Font.PLAIN, 12));
		menu.setMnemonic(KeyEvent.VK_F);
		
		for (JMenuItem  item : menuItems) {
			menu.add(item);
		}
		return menu;
	}

	private JMenuItem createNenuItem(String title) {
		JMenuItem item = new JMenuItem(title);
		item.setFont(new Font("宋体", Font.PLAIN, 12));
		item.addActionListener(this);
		
		return item;
	}

	@Override
	public void actionPerformed(ActionEvent e) {
		if (e.getActionCommand().equals("关闭")) {
			System.exit(0);
		} else if (e.getActionCommand().equals("日报选择...")) {
			parent.showFileChooser();
		} else if (e.getActionCommand().equals("账户设置...")) {
			parent.setEnabled(false);
			new SettingWindow(parent);
		}else if (e.getActionCommand().equals("关于")) {
			JOptionPane.showMessageDialog(null, "version 1.0");
		}
	}
}
